<template>
  <div class="body1">
    <div class="no-print el-button-print">
      <el-button @click="exportPDF">导出为pdf</el-button>
    </div>
    <div class="body2" id="pdfDom" :class="{ 'pdf-export': isPdfExport }">
      <div class="title">
        <div class="biaotididian">{{ agencyName }}</div>
        <div class="biaoti">行政处罚决定审批表</div>
      </div>
      <table class="tableStyle">
        <colgroup>
          <col width="15%">
          <col width="10%">
          <col width="20%">
          <col width="18%">
          <col width="15%">
          <col width="22%">
        </colgroup>
        <tbody>
          <tr>
            <td style="height: 50px; text-align: center;">立案案号</td>
            <td colspan="3">
              <el-input v-model="form.textarea1" :resize="'none'" autosize class="areaInputStyle" type="textarea"
                maxlength="30" />
            </td>
            <td style="text-align: center;">立案时间</td>
            <td>
              <editable-textarea :text="form.date1" param-type="YYYYMMDD1"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 50px;">案&nbsp&nbsp&nbsp&nbsp由</td>
            <td colspan="5">
              <el-input v-model="form.textarea2" :resize="'none'" autosize class="areaInputStyle" type="textarea"
                maxlength="54" />
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 50px;">案发地点</td>
            <td colspan="5">
              <el-input v-model="form.textarea3" :resize="'none'" type="textarea" autosize class="areaInputStyle"
                maxlength="54">
              </el-input>
            </td>
          </tr>
          <tr>
            <td rowspan="17" style="text-align: center;">当事人</td>
            <td rowspan="5" style="text-align: center;">个人</td>
            <td style="text-align: center;">姓&nbsp&nbsp&nbsp&nbsp名</td>
            <td>
              <el-input maxlength="5" v-model="form.textarea4" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
            <td style="text-align: center;">出生年月</td>
            <td>
              <editable-textarea :text="form.date2" param-type="YYYYMMDD2"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">性&nbsp&nbsp&nbsp&nbsp别</td>
            <td>
              <el-input maxlength="5" v-model="form.textarea5" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
            <td style="text-align: center;">联系电话</td>
            <td>
              <el-input maxlength="14" oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')"
                v-model="form.textarea6" :resize="'none'" type="textarea" autosize class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="height: 50px; text-align: center;">身份证或其他有效证件号码</td>
            <td colspan="3">
              <el-input maxlength="34" v-model="form.textarea7" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="height: 50px; text-align: center;">住&nbsp&nbsp&nbsp&nbsp址</td>
            <td colspan="3">
              <el-input maxlength="34" v-model="form.textarea8" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">工作单位</td>
            <td colspan="3">
              <el-input maxlength="17" v-model="form.textarea9" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td rowspan="8" style="text-align: center;">个体<br>工商<br>户</td>
            <td style="text-align: center;">字&nbsp&nbsp&nbsp&nbsp号</td>
            <td colspan="3">
              <privy-info-select-return-array v-model="form.textarea10" :isTable="true" maxLength="36" return-fields="A"
                :return-array-template="[
                  { name: 'textarea12', field: 'C' },
                  { name: 'textarea16', field: 'E' },
                  { name: 'textarea14', field: 'H' },
                ]" @select="selectUnitUpdateData">
              </privy-info-select-return-array>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">经营场所</td>
            <td colspan="3">
              <el-input maxlength="17" v-model="form.textarea11" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td rowspan="6" style="text-align: center;">经&nbsp;营&nbsp;者</td>
            <td style="text-align: center;">姓&nbsp&nbsp&nbsp&nbsp名</td>
            <td colspan="2">
              <el-input maxlength="11" v-model="form.textarea12" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">性&nbsp&nbsp&nbsp&nbsp别</td>
            <td colspan="2">
              <el-input maxlength="11" v-model="form.textarea13" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">出生年月</td>
            <td colspan="2">
              <editable-textarea :text="form.date3" param-type="YYYYMMDD3"
                @send-to-parent="receiveFromChild"></editable-textarea>
            </td>
          </tr>
          <tr>
            <td style="text-align: center;">联系电话</td>
            <td colspan="2">
              <el-input maxlength="23" oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')"
                v-model="form.textarea14" :resize="'none'" type="textarea" autosize class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 75px;">身份证或<br>其他有效<br>证件号码</td>
            <td colspan="2">
              <el-input maxlength="33" v-model="form.textarea15" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 75px;">住&nbsp&nbsp&nbsp&nbsp址</td>
            <td colspan="2">
              <el-input maxlength="33" v-model="form.textarea16" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td rowspan="4" style="text-align: center;">法人<br>和其他组织</td>
            <td style="text-align: center;height: 50px;">名&nbsp&nbsp&nbsp&nbsp称</td>
            <td colspan="3">
              <privy-info-select-return-array v-model="form.unitName" :isTable="true" maxLength="34" return-fields="A"
                :return-array-template="[
                  { name: 'companyLicense', field: 'B' },
                  { name: 'legalPerson', field: 'C' },
                  { name: 'legalPersonPosition', field: 'D' },
                  { name: 'companyAddress', field: 'E' },
                  { name: 'legalPersonPhone', field: 'H' },
                ]" @select="selectUnitUpdateData">
              </privy-info-select-return-array>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 50px;">法定代表人<br>或负责人</td>
            <td>
              <el-input maxlength="10" v-model="form.legalPerson" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
            <td style="text-align: center;">职&nbsp&nbsp&nbsp&nbsp务</td>
            <td>
              <el-input maxlength="14" v-model="form.legalPersonPosition" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 50px;">统一社会<br>信用代码</td>
            <td>
              <el-input maxlength="22" oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')"
                v-model="form.companyLicense" :resize="'none'" type="textarea" autosize class="areaInputStyle">
              </el-input>
            </td>
            <td style="text-align: center;">联系电话</td>
            <td>
              <el-input maxlength="28" oninput="this.value = this.value.replace(/[^a-zA-Z0-9_-]/g, '')"
                v-model="form.legalPersonPhone" :resize="'none'" type="textarea" autosize class="areaInputStyle">
              </el-input>
            </td>
          </tr>
          <tr>
            <td style="text-align: center; height: 50px;">住&nbsp&nbsp&nbsp&nbsp所</td>
            <td colspan="3">
              <el-input maxlength="34" v-model="form.companyAddress" :resize="'none'" type="textarea" autosize
                class="areaInputStyle">
              </el-input>
            </td>
          </tr>
        </tbody>
      </table>
      <div class="page-break"></div>
      <table class="tableStyle">
        <colgroup>
          <col width="15%">
          <col width="10%">
          <col width="20%">
          <col width="18%">
          <col width="15%">
          <col width="22%">
        </colgroup>
        <tbody>
          <tr style="height: 150px;">
            <td style="text-align: center;">具体违法<br>事&nbsp;&nbsp;&nbsp;&nbsp;实</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea23" :rows="textarea23Config.maxLines"
                @keydown.native="handleKeyDown('textarea23', $event)" @input="handleInput('textarea23', $event)"
                @paste.native="handlePaste('textarea23', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace;" wrap="soft" />
            </td>
          </tr>
          <tr style="height: 100px;">
            <td style="text-align: center;">相关证据</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea24" :rows="textarea24Config.maxLines"
                @keydown.native="handleKeyDown('textarea24', $event)" @input="handleInput('textarea24', $event)"
                @paste.native="handlePaste('textarea24', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace;" wrap="soft" />
            </td>
          </tr>
          <tr>
            <td style="height: 135px; text-align: center;">履行告知<br>及当事人<br>陈述申辩<br>或者听证<br>情&nbsp;&nbsp;&nbsp;&nbsp;况
            </td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea25" :rows="textarea25Config.maxLines"
                @keydown.native="handleKeyDown('textarea25', $event)" @input="handleInput('textarea25', $event)"
                @paste.native="handlePaste('textarea25', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace;" wrap="soft" />
            </td>
          </tr>
          <tr style="height: 125px;">
            <td style="text-align: center;">处罚依据</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea26" :rows="textarea26Config.maxLines"
                @keydown.native="handleKeyDown('textarea26', $event)" @input="handleInput('textarea26', $event)"
                @paste.native="handlePaste('textarea26', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace;" wrap="soft" />
            </td>
          </tr>

          <tr>
            <td style="height: 100px; text-align: center;">承办人<br>意&nbsp;&nbsp;见</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea27" :rows="textarea27Config.maxLines"
                @keydown.native="handleKeyDown('textarea27', $event)" @input="handleInput('textarea27', $event)"
                @paste.native="handlePaste('textarea27', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace; " wrap="soft" />
              <div
                style="position: absolute; bottom: 10px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; margin-top: 20px;">
                <div style="display: flex; align-items: flex-end;">
                  签名：
                  <SignatureField label="签名1" sign-type="sign1" :img-url="form.img1"
                    @update:imgUrl="form.img1 = $event" />
                </div>
                <div>
                  <editable-textarea :text="form.date4" param-type="YYYYMMDD4"
                    @send-to-parent="receiveFromChild"></editable-textarea>
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 100px;">
            <td style="text-align: center;">承办机构<br>意&nbsp;&nbsp;&nbsp;&nbsp;见</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea28" :rows="textarea28Config.maxLines"
                @keydown.native="handleKeyDown('textarea28', $event)" @input="handleInput('textarea28', $event)"
                @paste.native="handlePaste('textarea28', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace; " wrap="soft" />
              <div
                style="position: absolute; bottom: 10px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; margin-top: 20px;">
                <div style="display: flex; align-items: flex-end;">
                  签名：
                  <SignatureField label="签名2" sign-type="sign2" :img-url="form.img2"
                    @update:imgUrl="form.img2 = $event" />
                </div>
                <div>
                  <editable-textarea :text="form.date5" param-type="YYYYMMDD5"
                    @send-to-parent="receiveFromChild"></editable-textarea>
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 100px;">
            <td style="text-align: center;">法制部门<br>意&nbsp;&nbsp;&nbsp;&nbsp;见</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea29" :rows="textarea29Config.maxLines"
                @keydown.native="handleKeyDown('textarea29', $event)" @input="handleInput('textarea29', $event)"
                @paste.native="handlePaste('textarea29', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace; " wrap="soft" />
              <div
                style="position: absolute; bottom: 10px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; margin-top: 20px;">
                <div style="display: flex; align-items: flex-end;">
                  签名：
                  <SignatureField label="签名3" sign-type="sign3" :img-url="form.img3"
                    @update:imgUrl="form.img3 = $event" />
                </div>
                <div>
                  <editable-textarea :text="form.date6" param-type="YYYYMMDD6"
                    @send-to-parent="receiveFromChild"></editable-textarea>
                </div>
              </div>
            </td>
          </tr>
          <tr style="height: 100px;">
            <td style="text-align: center;">行政机关<br>负&nbsp;责&nbsp;人<br>意&nbsp;&nbsp;&nbsp;&nbsp;见</td>
            <td colspan="5" style="text-align: left;vertical-align: top; position: relative;">
              <el-input type="textarea" v-model="form.textarea30" :rows="textarea30Config.maxLines"
                @keydown.native="handleKeyDown('textarea30', $event)" @input="handleInput('textarea30', $event)"
                @paste.native="handlePaste('textarea30', $event)" class="el-textarea-hidden"
                style="white-space: pre;overflow-x: auto;font-family: monospace; " wrap="soft" />
              <div
                style="position: absolute; bottom: 10px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: flex-end; margin-top: 20px;">
                <div style="display: flex; align-items: flex-end;">
                  签名：
                  <SignatureField label="签名4" sign-type="sign4" :img-url="form.img4"
                    @update:imgUrl="form.img4 = $event" />
                </div>
                <div>
                  <editable-textarea :text="form.date7" param-type="YYYYMMDD7"
                    @send-to-parent="receiveFromChild"></editable-textarea>
                </div>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import EditableTextarea from "@/views/template/EditableTextarea";
import { agencyName, sealName } from "../../utils/publicName.js";
import PrivyInfoSelectReturnArray from "@/views/template/PrivyInfoSelectReturnArray";
import SignatureField from "@/views/template/SignatureField";
import { createInputLimiter } from '@/utils/limitInput';


export default {
  components: {
    EditableTextarea,
    SignatureField,
    PrivyInfoSelectReturnArray,
  },

  data() {
    return {
      agencyName: agencyName,
      sealName: sealName,
      form: {},
      isPdfExport: false, // 控制打印样式
      textarea23Config: {
        maxLines: 6,
        charsPerLine: 27 * 2,
        maxLength: 6 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea24Config: {
        maxLines: 4,
        charsPerLine: 27 * 2,
        maxLength: 4 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea25Config: {
        maxLines: 5,
        charsPerLine: 27 * 2,
        maxLength: 5 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea26Config: {
        maxLines: 5,
        charsPerLine: 27 * 2,
        maxLength: 5 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea27Config: {
        maxLines: 2,
        charsPerLine: 27 * 2,
        maxLength: 2 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea28Config: {
        maxLines: 2,
        charsPerLine: 27 * 2,
        maxLength: 2 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea29Config: {
        maxLines: 2,
        charsPerLine: 27 * 2,
        maxLength: 2 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },
      textarea30Config: {
        maxLines: 2,
        charsPerLine: 27 * 2,
        maxLength: 2 * 27 * 2,
        inputLimiter: null,
        displayText: ''
      },

    };
  },
  created() {
    //调用父页面函数获取文书数据
    window.parent.getTemplateData((data) => {
      this.form = data;
    })
    //将方法暴露在初始化加载中
    window.postForm = () => {
      this.postForm();
    }
    this.textarea23Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea23Config.maxLines,
      charsPerLine: this.textarea23Config.charsPerLine,
      maxLength: this.textarea23Config.maxLength,
      propName: 'form.textarea23'
    });
    this.textarea24Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea24Config.maxLines,
      charsPerLine: this.textarea24Config.charsPerLine,
      maxLength: this.textarea24Config.maxLength,
      propName: 'form.textarea24'
    });
    this.textarea25Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea25Config.maxLines,
      charsPerLine: this.textarea25Config.charsPerLine,
      maxLength: this.textarea25Config.maxLength,
      propName: 'form.textarea25'
    });
    this.textarea26Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea26Config.maxLines,
      charsPerLine: this.textarea26Config.charsPerLine,
      maxLength: this.textarea26Config.maxLength,
      propName: 'form.textarea26'
    });
    this.textarea27Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea27Config.maxLines,
      charsPerLine: this.textarea27Config.charsPerLine,
      maxLength: this.textarea27Config.maxLength,
      propName: 'form.textarea27'
    });
    this.textarea28Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea28Config.maxLines,
      charsPerLine: this.textarea28Config.charsPerLine,
      maxLength: this.textarea28Config.maxLength,
      propName: 'form.textarea28'
    });
    this.textarea29Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea29Config.maxLines,
      charsPerLine: this.textarea29Config.charsPerLine,
      maxLength: this.textarea29Config.maxLength,
      propName: 'form.textarea29'
    });
    this.textarea30Config.inputLimiter = createInputLimiter(this, {
      maxLines: this.textarea30Config.maxLines,
      charsPerLine: this.textarea30Config.charsPerLine,
      maxLength: this.textarea30Config.maxLength,
      propName: 'form.textarea30'
    });

  },
  methods: {
    getConfigName(field) {
      switch (field) {
        case 'textarea23':
          return this.textarea23Config;
        case 'textarea24':
          return this.textarea24Config;
        case 'textarea25':
          return this.textarea25Config;
        case 'textarea26':
          return this.textarea26Config;
        case 'textarea27':
          return this.textarea27Config;
        case 'textarea28':
          return this.textarea28Config;
        case 'textarea29':
          return this.textarea29Config;
        case 'textarea30':
          return this.textarea30Config;
      }
    },
    handleKeyDown(field, e) {
      const config = this.getConfigName(field);
      config.inputLimiter.handleKeyDown(e);
    },
    handleInput(field, value) {
      const config = this.getConfigName(field);
      this.form[field] = config.inputLimiter.handleInput(value);
    },
    handlePaste(field, e) {
      const config = this.getConfigName(field);
      config.inputLimiter.handlePaste(e);
    },
    // 导出为pdf
    exportPDF() {
      this.savePDF()
        .then((blob) => {
          const blobUrl = URL.createObjectURL(blob);

          // 先预览
          const previewWindow = window.open(blobUrl, '_blank');

          // 自动下载
          const fileName = `行政处罚决定审批表.pdf`;
          const downloadLink = document.createElement('a');
          downloadLink.href = blobUrl;
          downloadLink.download = fileName;
          document.body.appendChild(downloadLink);
          downloadLink.click();
          document.body.removeChild(downloadLink);

          // 监听预览窗口关闭后释放内存
          if (previewWindow) {
            const timer = setInterval(() => {
              if (previewWindow.closed) {
                clearInterval(timer);
                URL.revokeObjectURL(blobUrl);
              }
            }, 1000);
          } else {
            setTimeout(() => URL.revokeObjectURL(blobUrl), 10000); // 兜底释放
          }
        })
        .catch(error => {
          console.error('导出PDF出错:', error);
          alert('导出失败，请重试或联系管理员');
        });
    },
    savePDF() {
      this.isPdfExport = true; // 激活PDF样式
      return new Promise((resolve, reject) => {
        this.$nextTick(() => {
          import('html2pdf.js').then((module) => {
            const html2pdf = module.default;

            //获取所有需要替换的 el-input
            const elInputs = document.querySelectorAll('.el-input__inner, .el-textarea__inner');

            //存储原始元素和它们的父节点，方便后续恢复
            const originalElements = [];

            elInputs.forEach((input) => {
              const div = document.createElement('div');
              div.style.whiteSpace = 'pre-wrap'; // 保留换行
              div.style.fontFamily = '仿宋';
              div.style.fontSize = '5mm';
              div.textContent = input.value; // 保留原内容（自动处理 \n 换行）
              div.style.lineHeight = '1.3';

              // 替换 el-input，并存储原始元素
              originalElements.push({
                parent: input.parentNode,
                original: input,
                replacement: div,
              });
              input.parentNode.replaceChild(div, input);
            });

            // 配置选项
            const opt = {
              margin: 0,
              image: {
                type: 'jpeg',
                quality: 0.98
              },
              html2canvas: {
                scale: 2,
                logging: false,
                useCORS: true
              },
              jsPDF: {
                unit: 'mm',
                format: 'a4',
                orientation: 'portrait'
              }
            };

            const element = document.getElementById('pdfDom');

            // 生成PDF Blob对象
            html2pdf()
              .set(opt)
              .from(element)
              .toPdf()
              .get('pdf')
              .then((pdf) => {
                const blob = pdf.output('blob');

                resolve(blob); // 返回Blob对象
              })
              .catch((error) => {
                reject(error);
              })
              .finally(() => {
                this.isPdfExport = false; // 恢复原始样式
                // 恢复原始input
                originalElements.forEach(({ parent, original, replacement }) => {
                  parent.replaceChild(original, replacement);
                });
              });
          }).catch((error) => {
            reject(error);
            this.isPdfExport = false;
            originalElements.forEach(({ parent, original, replacement }) => {
              parent.replaceChild(original, replacement);
            });
          });
        });
      });
    },
    //父页面提交按钮将调用此方法，此方法将文书数据回传到父页面的请求方法中
    postForm() {
      this.savePDF()
        .then((blob) => {


          // 创建FormData并添加文件
          const formData = new FormData();
          formData.append('file', blob, '行政处罚决定审批表.pdf');

          window.parent.postTemplateDate(this.form, formData);
        })
        .catch(error => {
          console.error('整个保存PDF出错:', error);
        });
    },
    //选择日期时间
    receiveFromChild(data, type) {
      const TypeMap = {
        'YYYYMMDD1': 'date1',
        'YYYYMMDD2': 'date2',
        'YYYYMMDD3': 'date3',
        'YYYYMMDD4': 'date4',
        'YYYYMMDD5': 'date5',
        'YYYYMMDD6': 'date6',
        'YYYYMMDD7': 'date7',
      };
      if (TypeMap[type]) {
        this.form[TypeMap[type]] = data;
      }
    },
    // 选择单位
    selectUnitUpdateData(data) {
      data.forEach(item => {
        this.form[item.name] = item.value;
      })
    },
  },
  //能否编辑判断
  mounted() {
    window.parent.changeTemplateDow();
  },
};
</script>

<style scoped>
:deep(.el-button-print .el-button) {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: auto;
  min-width: 100px;
  height: auto;
  padding: 8px 15px;
  background: #fff !important;
  color: #000 !important;
  border: none;
}

:deep(.el-textarea__inner) {
  box-shadow: 0 0 0 0;
  color: black;
  padding: 0;
  font-family: "仿宋", serif;
  font-size: 5mm;
  overflow-y: hidden;
  line-height: 1.3;
}

:deep(.el-textarea-hidden .el-textarea__inner) {
  box-shadow: 0 0 0 0;
  color: black;
  padding: 0;
  font-family: "仿宋", serif;
  font-size: 5mm;
  overflow-y: hidden !important;
  resize: none !important;
  height: auto !important;
}

.input-container {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}

.inputStyleNoLine {
  border: none;
  outline: none;
  padding: 0px;
}

.typeSpan {
  cursor: pointer;
  font-size: 5mm;
}
</style>
